<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="变压器ID" prop="equipId">
            <el-input v-model="form.equipId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="导入批次" prop="recordId">
            <el-input v-model="form.recordId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="介质损耗因数" prop="tanDelta">
            <el-input v-model="form.tanDelta" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="复介电常数实部" prop="eReal">
            <el-input v-model="form.eReal" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="复介电常数虚部" prop="eImaginary">
            <el-input v-model="form.eImaginary" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="复电容实部" prop="cReal">
            <el-input v-model="form.cReal" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="复电容虚部" prop="cImaginary">
            <el-input v-model="form.cImaginary" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建人" prop="createBy">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新人">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="频率" prop="frequency">
            <el-input v-model="form.frequency" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="功率因数" prop="powerFactor">
            <el-input v-model="form.powerFactor" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="equipId" label="变压器ID" />
        <el-table-column prop="recordId" label="导入批次" />
        <el-table-column prop="tanDelta" label="介质损耗因数" />
        <el-table-column prop="eReal" label="复介电常数实部" />
        <el-table-column prop="eImaginary" label="复介电常数虚部" />
        <el-table-column prop="cReal" label="复电容实部" />
        <el-table-column prop="cImaginary" label="复电容虚部" />
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="frequency" label="频率" />
        <el-table-column prop="powerFactor" label="功率因数" />
        <el-table-column v-if="checkPer(['admin','fdsData:edit','fdsData:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudFdsData from '@/api/fdsData'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { getToken } from '@/utils/auth'

const defaultForm = { id: null, equipId: null, recordId: null, tanDelta: null, eReal: null, eImaginary: null, cReal: null, cImaginary: null, createBy: null, updateBy: null, createTime: null, updateTime: null, frequency: null, powerFactor: null }
export default {
  name: 'FdsData',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '历史数据查询', url: 'api/fdsData', idField: 'id', sort: 'id,desc', crudMethod: { ...crudFdsData }})
  },
  data() {
    return {
      headers: {
        'Authorization': getToken()
      },
      permission: {
        add: ['admin', 'fdsData:add'],
        edit: ['admin', 'fdsData:edit'],
        del: ['admin', 'fdsData:del']
      },
      rules: {
        equipId: [
          { required: true, message: '变压器ID不能为空', trigger: 'blur' }
        ],
        recordId: [
          { required: true, message: '导入批次不能为空', trigger: 'blur' }
        ],
        tanDelta: [
          { required: true, message: '介质损耗因数不能为空', trigger: 'blur' }
        ],
        eReal: [
          { required: true, message: '复介电常数实部不能为空', trigger: 'blur' }
        ],
        eImaginary: [
          { required: true, message: '复介电常数虚部不能为空', trigger: 'blur' }
        ],
        cReal: [
          { required: true, message: '复电容实部不能为空', trigger: 'blur' }
        ],
        cImaginary: [
          { required: true, message: '复电容虚部不能为空', trigger: 'blur' }
        ],
        createBy: [
          { required: true, message: '创建人不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        frequency: [
          { required: true, message: '频率不能为空', trigger: 'blur' }
        ],
        powerFactor: [
          { required: true, message: '功率因数不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
